package com.yocard.yxyd.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.webkit.ValueCallback;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.gyf.barlibrary.ImmersionBar;
import com.ogaclejapan.smarttablayout.SmartTabLayout;
import com.yocard.yxyd.R;
import com.yocard.yxyd.adapter.InviteRecordsFragmentAdapter;
import com.yocard.yxyd.ui.activity.base.SimpleActivity;
import com.yocard.yxyd.ui.fragment.InviteRecordListFragment;
import com.yocard.yxyd.utils.util.ActivityUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created on 2019/5/28.
 * 邀请记录列表
 */
public class InviteRecordsActivity extends SimpleActivity {

    @BindView(R.id.tab_layout)
    SmartTabLayout tabLayout;
    @BindView(R.id.view_pager)
    ViewPager viewPager;
//    @BindView(R.id.rl_head_layout)
//    RelativeLayout rlHeadLayout;
    protected String csmId;
    int headHeight;
    int currentTabIndex = 0;
    InviteRecordsFragmentAdapter mAdapter;

    @Override
    protected int getLayout() {
        return R.layout.act_invite_records;
    }

    @Override
    protected void initEventAndData() {
        ImmersionBar.with(this).statusBarColor(R.color.white)
                .statusBarDarkFont(true).navigationBarColor(R.color.white).init();
//        rlHeadLayout.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
//            @Override
//            public void onGlobalLayout() {
//                headHeight = rlHeadLayout.getHeight();
//                rlHeadLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
//            }
//        });

//        ViewGroup.LayoutParams layoutParams = rlHeadLayout.getLayoutParams();
        ValueCallback<Integer> callback = new ValueCallback<Integer>() {
            @Override
            public void onReceiveValue(Integer value) {
//                layoutParams.height = headHeight + value;
//                rlHeadLayout.requestLayout();
            }
        };

        mAdapter = new InviteRecordsFragmentAdapter(getSupportFragmentManager(), callback);
        viewPager.setAdapter(mAdapter);
        tabLayout.setViewPager(viewPager);
        tabLayout.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int i, float v, int i1) {

            }

            @Override
            public void onPageSelected(int i) {
                currentTabIndex = i;
                Fragment fragmentAt = mAdapter.getFragmentAt(currentTabIndex);
                if (fragmentAt instanceof InviteRecordListFragment) {
                    InviteRecordListFragment fragment = (InviteRecordListFragment) fragmentAt;
                    fragment.refresh();
                }
            }

            @Override
            public void onPageScrollStateChanged(int i) {

            }
        });
    }

    @OnClick({R.id.iv_back})
    public void onClick(View view){
        switch (view.getId()){
            case R.id.iv_back:
                ActivityUtils.finishActivity(this);
                break;
        }
    }

}
